from django.http import JsonResponse
from rest_framework import status
from Model.models import Page as P
res = dict()


def Page(request):
    res.clear()
    try:
        if request.method == 'GET':
            return getPage(request)
        elif request.method == 'POST':
            pass
        elif request.method == 'PUT':
            pass
        elif request.method == 'DELETE':
            pass
    except Exception as e:
        print(e)
        res['status'] = 200
        res['message'] = '请求错误!'
        return JsonResponse(res, status=status.HTTP_400_BAD_REQUEST)


# 获取页面信息
def getPage(request):
    page_list = P.objects.all()
    res['status'] = 200
    res['data'] = list(page_list.values())
    res['message'] = '请求成功'
    return JsonResponse(res, status=status.HTTP_200_OK)
